package org.szgb.console.sys.todo.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.format.annotation.DateTimeFormat;
import org.szgb.console.sys.user.entity.SysUser;
import org.szgb.core.base.entity.BeanEntity;

import java.io.Serial;
import java.time.LocalDateTime;
import java.util.List;

@EqualsAndHashCode(callSuper = true)
@Data
public class SysTodo extends BeanEntity<SysTodo> {
    @Serial
    private static final long serialVersionUID = 1L;
    private Integer type;
    private String groupId;
    private SysUser user;
    private String title;
    private String content;
    private Integer sign;
    private String parameter;
    private Boolean isDeal;

    public SysTodo() {
    }

    public SysTodo(String id) {
        this.setId(id);
    }

    public SysTodo(SysTodoFindDto sysTodoFindDto) {
        this.setUser(new SysUser(sysTodoFindDto.getUserId()));
        this.setSign(sysTodoFindDto.getSign());
        this.setIsDeal(sysTodoFindDto.getIsDeal());
    }

    @Data
    @Schema(title = "待办信息", description = "待办信息")
    public static class SysTodoView {
        @Schema(description = "ID")
        private String id;
        @Schema(description = "标题")
        private String title;
        @Schema(description = "内容")
        private String content;
        @Schema(description = "待办标志")
        private Integer sign;
        @Schema(description = "参数")
        private String parameter;
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
        @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        @Schema(description = "创建时间")
        private LocalDateTime createdAt;
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
        @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        @Schema(description = "更新时间")
        private LocalDateTime updatedAt;
        @Schema(description = "创建人id")
        private String createdById;
        @Schema(description = "创建人姓名")
        private String createdByName;
        @Schema(description = "更新人id")
        private String updatedById;
        @Schema(description = "更新人姓名")
        private String updatedByName;

        public SysTodoView(SysTodo sysTodo) {
            this.id = sysTodo.getId();
            this.title=sysTodo.getTitle();
            this.content=sysTodo.getContent();
            this.sign=sysTodo.getSign();
            this.parameter=sysTodo.getParameter();
            this.createdAt = sysTodo.getCreatedAt();
            this.updatedAt = sysTodo.getUpdatedAt();
            if (sysTodo.getCreatedBy() != null) {
                this.createdById = sysTodo.getCreatedBy().getId();
                this.createdByName = sysTodo.getCreatedBy().getName();
            }
            if (sysTodo.getUpdatedBy() != null) {
                this.updatedById = sysTodo.getUpdatedBy().getId();
                this.updatedByName = sysTodo.getUpdatedBy().getName();
            }
        }

        public static List<SysTodo.SysTodoView> getViewListFromList(List<SysTodo> sysTodoList) {
            return sysTodoList.stream().map(SysTodo.SysTodoView::new).toList();
        }
    }


    @Data
    @Schema(title = "待办查询表单", description = "待办查询参数")
    public static class SysTodoFindDto {
        @Schema(description = "待办标志")
        private Integer sign;
        @Schema(description = "用户id")
        private String userId;
        @Schema(description = "是否处理")
        private Boolean isDeal;

        public SysTodo toSysTodo() {
            return new SysTodo(this);
        }
    }

    @Data
    @Schema(title = "知会处理表单", description = "知会处理参数")
    public static class SysTodoApprovalDto {
        @Schema(description = "待办id")
        private String id;
    }
}
